/*
// --------------------------
// Copyright 2008 Daniel Gray
// --------------------------
// This file is part of Kale.
//
// Kale is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Kale is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Kale.  If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------
// Filename          : UnitTestData.sql
// Author            : Daniel Gray
// Created           : 01/05/2008
// --------------------------------------------------------
*/

/* Common values */
DECLARE @defaultPassword binary(256);
SET @defaultPassword = 0xB109F3BBBC244EB82441917ED06D618B9008DD09B3BEFD1B5E07394C706A8BB980B1D7785E5976EC049B46DF5F1326AF5A2EA6D103FD07C95385FFAB0CACBC86;

/* Create User Groups */

DECLARE @everyoneGroupUid uniqueidentifier
DECLARE @administratorsGroupUid uniqueidentifier
DECLARE @usersGroupUid uniqueidentifier

SET @everyoneGroupUid = NEWID();
SET @administratorsGroupUid = NEWID();
SET @usersGroupUid = NEWID();

INSERT INTO UserGroup VALUES (@everyoneGroupUid, 'Everyone');
INSERT INTO UserGroup VALUES (@administratorsGroupUid, 'Administrators');
INSERT INTO UserGroup VALUES (@usersGroupUid, 'Users');

/* Create User Roles */

DECLARE @createUsersRoleUid uniqueidentifier
DECLARE @editUsersRoleUid uniqueidentifier
DECLARE @deleteUsersRoleUid uniqueidentifier

SET @createUsersRoleUid = NEWID();
SET @editUsersRoleUid = NEWID();
SET @deleteUsersRoleUid = NEWID();

INSERT INTO UserRole VALUES (@createUsersRoleUid, 'Create Users');
INSERT INTO UserRole VALUES (@editUsersRoleUid, 'Edit Users');
INSERT INTO UserRole VALUES (@deleteUsersRoleUid, 'Delete Users');

DECLARE @createUserGroupsRoleUid uniqueidentifier
DECLARE @editUserGroupsRoleUid uniqueidentifier
DECLARE @deleteUserGroupsRoleUid uniqueidentifier

SET @createUserGroupsRoleUid = NEWID();
SET @editUserGroupsRoleUid = NEWID();
SET @deleteUserGroupsRoleUid = NEWID();

INSERT INTO UserRole VALUES (@createUserGroupsRoleUid, 'Create User Groups');
INSERT INTO UserRole VALUES (@editUserGroupsRoleUid, 'Edit User Groups');
INSERT INTO UserRole VALUES (@deleteUserGroupsRoleUid, 'Delete User Groups');

/* Create Users */

DECLARE @anonymousUserUid uniqueidentifier
DECLARE @administratorUserUid uniqueidentifier

SET @anonymousUserUid = NEWID();
SET @administratorUserUid = NEWID();

INSERT INTO [User] VALUES (@anonymousUserUid, 'Anonymous', @defaultPassword, null);
INSERT INTO [User] VALUES (@administratorUserUid, 'Administrator', @defaultPassword, null);

/* Assign Users to Groups */

INSERT INTO [User_UserGroup] VALUES (NEWID(), @anonymousUserUid, @everyoneGroupUid);

INSERT INTO [User_UserGroup] VALUES (NEWID(), @administratorUserUid, @administratorsGroupUid);
INSERT INTO [User_UserGroup] VALUES (NEWID(), @administratorUserUid, @usersGroupUid);

/* Assign Roles to Groups */

INSERT INTO [UserGroup_UserRole] VALUES (NEWID(), @administratorsGroupUid, @createUsersRoleUid);
INSERT INTO [UserGroup_UserRole] VALUES (NEWID(), @administratorsGroupUid, @editUsersRoleUid);
INSERT INTO [UserGroup_UserRole] VALUES (NEWID(), @administratorsGroupUid, @deleteUsersRoleUid);

INSERT INTO [UserGroup_UserRole] VALUES (NEWID(), @administratorsGroupUid, @createUserGroupsRoleUid);
INSERT INTO [UserGroup_UserRole] VALUES (NEWID(), @administratorsGroupUid, @editUserGroupsRoleUid);
INSERT INTO [UserGroup_UserRole] VALUES (NEWID(), @administratorsGroupUid, @deleteUserGroupsRoleUid);

/* Assign Groups to Groups */

INSERT INTO [UserGroup_UserGroup] VALUES (NEWID(), @everyoneGroupUid, @administratorsGroupUid);

/* User with role */

DECLARE @userWithRoleUid uniqueidentifier
SET @userWithRoleUid = NEWID();

INSERT INTO [User] VALUES (@userWithRoleUid, 'UserWithRole',@defaultPassword,null);
INSERT INTO [User_UserRole] VALUES (NEWID(), @userWithRoleUid, @createUsersRoleUid);